#ifndef CCOLORPANEL_H
#define CCOLORPANEL_H

#include <QWidget>
#include <QToolButton>

class CColorButton : public QToolButton
{
    Q_OBJECT
public:
    explicit CColorButton(const QColor& color, bool showColorDialog = true, QWidget *parent = nullptr);
    ~CColorButton() override;

public:
    void SetColor(const QColor& color);
    const QColor& GetColor() const;

    void setBgColor(QColor color);  //设置背景颜色
    void SetSize(const QSize &size)
    {
        m_size = size;
        resize(m_size);
    }

protected:
    void paintEvent(QPaintEvent *) override;
    virtual void enterEvent(QEvent *event) override;
    virtual void leaveEvent(QEvent *event) override;

public slots:
    void OnClick();

signals:
    void colorChange(const QColor& color);

private:
    void Init();

private:
    QColor m_color = Qt::white;
    QWidget *m_pColorShow;
    bool m_bShowColorDialog;
    QSize m_size;
    QCursor m_cursor;
};

class CColorPanel : public QWidget
{
    Q_OBJECT
public:
    explicit CColorPanel(QWidget *parent = nullptr);

protected Q_SLOTS:
    void SmallColorSel(const QColor& color);
protected:
    void paintEvent(QPaintEvent *) override;
signals:
    void ColorSel(const QColor& color);
private:
    void Init();
private:
    CColorButton m_MainColorButton;
};

#endif // CCOLORPANEL_H
